package com.wxmit.module.system.domain.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.wxmit.system.domain.LoginUser;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * OnlineUserDTO
 *
 * @author huangxiong
 * @version V1.0
 * @date 2022/12/9 17:31
 */
@Data
@Accessors(chain = true)
public class OnlineUserDTO {

    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    private String sessionId;

    private String username;

    private String ip;

    private String location;

    private String os;

    @JsonFormat(pattern = "yyyy-MM-dd hh:mm",timezone="GMT+8")
    private Date loginTime;

    public OnlineUserDTO setByLoginUser(LoginUser loginUser) {
        setUserId(loginUser.getId());
        setUsername(loginUser.getUsername());
        setIp(loginUser.getIpaddr());
        setLocation(loginUser.getLoginLocation());
        setOs(loginUser.getOs());
        return this;
    }
}
